package com.longtop.framework.sys.file.context;

import java.io.Serializable;
import java.util.Map;

import com.longtop.framework.common.Message;
import com.longtop.framework.security.BaseUncheckedException;

/**
 * FileContext类，用于存放上传文件等相关内容。具体见FileDispatcher
 * 
 */
public class FileContext implements Serializable {
	/**
	 * 
	 */
	private static final long serialVersionUID = -1828382368487920245L;

	protected Map<String, Object> context;

	public FileContext(Map<String, Object> context) {
		this.context = context;
	}

	static ThreadLocal<FileContext> fileContext = new ThreadLocal<FileContext>();

	public Map<String, Object> getContext() {
		return context;
	}

	public void setContext(Map<String, Object> context) {
		this.context = context;
	}

	public static void setFileContext(FileContext ctx) {
		fileContext.set(ctx);
	}

	public static FileContext getFileContext() {
		return fileContext.get();
	}

	public int getMaxExportSize() {
		int size = 0;
		String maxsize = Message.getMessage("excel.export.maxsize");
		if (maxsize.equals("")) {
			throw new BaseUncheckedException("请检查【applicationMessage_zh_CN.properties】配置文件,添加导出excel最大限制数【excel.export.maxsize】。");
		}
		try {
			size = Integer.parseInt(maxsize);
		} catch (Exception e) {
			throw new BaseUncheckedException("请检查【applicationMessage_zh_CN.properties】配置文件,导出excel最大限制数【excel.export.maxsize】必须为数字。");
		}
		return size;
	}

}
